package com.atguigu.day17.treeset.exer;

import org.junit.Test;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/21 10:12
 * @注释
 */
public class TreeSetTest {
    @Test
    public void test01(){
        Student s1 = new Student("张三", 18,99.3);
        Student s2 = new Student("李四", 25,99.5);
        Student s3 = new Student("王五", 33,99.9);
        Student s4 = new Student("赵六", 11,99.7);

        Comparator<Student> c1 = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.score, o2.score);
            }
        };

        TreeSet<Student> treeSet = new TreeSet<>(c1);
        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.add(s4);

        for (Student student : treeSet) {
            System.out.println(student);
        }
    }
}
